Partial Class pages_Languages_Language : Inherits CPage

#Region "Querystring"
    Public ReadOnly Property LanguageId() As Byte
        Get
            Return CWeb.RequestByte("languageId")
        End Get
    End Property
    Public ReadOnly Property IsEdit() As Boolean
        Get
            Return LanguageId > 0
        End Get
    End Property
#End Region

#Region "Members"
    Private m_language As CLanguage
#End Region

#Region "Data"
    Public ReadOnly Property [Language]() As CLanguage
        Get
            If IsNothing(m_language) Then
                If IsEdit Then
                    m_language = CLanguage.Cache.GetById(LanguageId)
                    If IsNothing(m_language) Then CSitemap.RecordNotFound("Language", LanguageId)
                Else
                    m_language = New CLanguage
                    'Inserts: set parentId here (if applicable)
                End If
            End If
            Return m_language
        End Get
    End Property
#End Region

#Region "Navigation"
    Private Sub Refresh()
        Response.Redirect(CSitemap.LanguageEdit(Me.Language.LanguageId))
    End Sub
    Private Sub ReturnToList()
        Response.Redirect(CSitemap.Languages)
    End Sub
#End Region

#Region "Event Handlers - Page"
    Protected Overrides Sub PageInit()

        'Page Title
        If IsEdit Then            
            Me.Title = "Language Details"
        Else
            Me.Title = "Create New Language"
        End If
                
        'Textbox logic
        'Me.Form.DefaultFocus = txtLanguageName.Textbox.ClientID;
        Me.Form.DefaultButton = btnSave.UniqueID   'txtLanguageName.OnReturnPress(btnSave)

        'Button Text
        btnDelete.Visible = IsEdit
        If IsEdit Then btnCancel.Text = "Back" Else btnSave.Text = "Create Language"
        If IsEdit Then AddButton(CSitemap.LanguageAdd(), "Create a new Language")

    End Sub
    Protected Overrides Sub PageLoad()
        If Page.IsPostback Then Exit Sub

        LoadLanguage()
    End Sub
#End Region

#Region "Event Handlers - Form"
    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Not Me.IsValid() Then Exit Sub
        SaveLanguage()
        Refresh()
    End Sub
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        ReturnToList()
    End Sub
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Me.Language.Delete()
            'CCache.ClearCache()
        ReturnToList()        
    End Sub
#End Region

#Region "Private - Load/Save"
    Protected Sub LoadLanguage()
        With Me.Language
            txtLanguageName.Text = .LanguageName
            txtLanguageNative.Text = .LanguageNative
        End With
    End Sub
    Protected Sub SaveLanguage()
        With Me.Language
            .LanguageName = txtLanguageName.Text
            .LanguageNative = txtLanguageNative.Text

            .Save()
        End With
            'CCache.ClearCache()
    End Sub
#End Region


End Class
